#include "log.h"

const char * get_time() {
    static char ret_date[64];
    struct timeval tv_begin;
    gettimeofday(&tv_begin, NULL);

    struct tm *date = localtime(&tv_begin.tv_sec);
    memset(ret_date, 0, sizeof(ret_date));
    sprintf(ret_date, "Date|%d|%d|%d|%d:%d:%d.%3d ",date->tm_year + 1900,date->tm_mon + 1,
            date->tm_mday,date->tm_hour,date->tm_min,date->tm_sec, tv_begin.tv_usec/1000);

    return ret_date;
}

void Log(const char * file_name,const char * func_name, int line,const char * format, ...) {
    fprintf(stderr, "%s%s|%s|line:%d|", get_time(), file_name, func_name, line);

    va_list list;
    va_start(list, format);
    vfprintf(stderr,format, list);
    va_end(list);
    fflush(stderr);
}
